//
//  CollectionView.swift
//  JLUIKit
//
//  Created by Jiang Chencheng on 2024/8/15.
//

import UIKit

open class JLCollectionView: UICollectionView {
    
    override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: layout)
        backgroundColor = .clear
    }
    
    @available(*, unavailable)
    public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
    
}

public extension JLCollectionView {
    func register<CellClass: JLCollectionViewCell>(_ cellClass: CellClass.Type) {
        register(cellClass, forCellWithReuseIdentifier: cellClass.cellID)
    }

    func dequeueReusableCell<CellClass: JLCollectionViewCell>(for indexPath: IndexPath) -> CellClass {
        guard let cell = dequeueReusableCell(withReuseIdentifier: CellClass.cellID, for: indexPath) as? CellClass else { fatalError("\(CellClass.cellID) dequeue for \(indexPath) error") }
        return cell
    }
}
